package com.fwmagic.dp._7._7_2;

import java.util.ArrayList;

public class Thing implements Cloneable {

    //定义一个私有变量
    private ArrayList arrayList = new ArrayList();

    public Thing() {
        System.out.println("构造函数被执行了……");
    }

    //设置arrayList的值
    public void setValue(String value) {
        this.arrayList.add(value);
    }

    //获取arrayList的值
    public ArrayList getValue() {
        return this.arrayList;
    }

    @Override
    protected Thing clone() {
        Thing thing = null;
        try {
            //浅拷贝，只会拷贝基本类型，byte short int long double …… String
            thing = (Thing) super.clone();
            //深拷贝，arrayList不同对象互不影响
            this.arrayList = (ArrayList<String>)this.arrayList.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return thing;
    }
}
